import Cookies from "js-cookie";

/**
 * CookieUtil常用的一些工具类
 */
export function setCookie(name: any, value: any, days: any) {
    let exp = new Date();
    exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
    // document.cookie = name + "=" + escape(value) + ";expires=" + exp.toUTCString();
    Cookies.set(name, value, {expires: days})
}

export function setTokenCookie(name: any, value: any, days: any) {
    Cookies.set(name, value, {expires: days})
}
export function getCookie(name: any) {
    let reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)")
    let arr = document.cookie.match(reg)
    if (arr) {
        return unescape(arr[2])
    } else {
        return null
    }
}

export function delCookie(name: any) {
    let exp = new Date();
    exp.setTime(exp.getTime() - 1);
    let cal = getCookie(name);
    if (cal != null)
        document.cookie = name + "=" + cal + ";expires=" + exp.toUTCString() + ";path=/";
}
